import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import './assets/style/im.scss';
import './assets/iconfont/iconfont.css';

import httpRequest from './api/httpRequest';
import * as socketApi from './api/wssocket';
import * as messageType from './api/messageType';
import emotion from './api/emotion.js';
import element from './api/element.js';
import store from './store';
import * as  enums from './api/enums.js';
import * as  date from './api/date.js';
import './utils/directive/dialogDrag';
import { createI18n } from "./utils/i18n/index"; //文件中新建的i18n文件

Vue.use(ElementUI);
// 挂载全局
Vue.prototype.$wsApi = socketApi;
Vue.prototype.$msgType = messageType
Vue.prototype.$date = date;
Vue.prototype.$http = httpRequest // http请求方法
Vue.prototype.$emo = emotion; // emo表情
Vue.prototype.$elm = element; // 元素操作
Vue.prototype.$enums = enums; // 枚举
Vue.prototype.$eventBus = new Vue(); // 全局事件
Vue.config.productionTip = false;
Vue.prototype.$ipcRenderer = window.require('electron').ipcRenderer;
Vue.prototype.$changeLanguage = function (e) {
  let showMessage = true;
  if (!e) {
    showMessage = false;
    e = localStorage.getItem('locale') ? localStorage.getItem('locale') : 'zh-CN'
    // this.languageStore.setLanguage(e);
  }
  // 将语言数据保存到缓存中
  localStorage.setItem('locale', e);
  // 更新 i18n 的语言设置
  this.$i18n.locale = e;
  if (showMessage) this.$message.success(this.$t('切换成功'))
}

// 浏览器兼容性处理
if (typeof window.ClipboardItem === 'undefined') {
  window.ClipboardItem = class MockClipboardItem {
    constructor(data) {
      this.data = data
    }
    get types() {
      return Object.keys(this.data)
    }
    async getType(type) {
      return this.data[type]
    }
  }
}
async function bootstrap() {
  const i18n = await createI18n(); // 等待异步加载完成
  new Vue({
    el: '#app',
    i18n, //使用国际化
    // 配置路由
    router,
    store,
    render: h => h(App)
  })
}

bootstrap();